package com.mediacloud.app.newsmodule.fragment.newslist

import android.content.Context
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import com.mediacloud.app.newsmodule.R

@JvmOverloads
fun generateDividerDrawable(context: Context,listWidth:Int,color:Int=Color.RED,dotWith:Int=2):Drawable
{
    val bitmap = Bitmap.createBitmap(listWidth, context.resources.getDimensionPixelOffset(R.dimen.dimen1), Bitmap.Config.ARGB_8888)
    var drawable=BitmapDrawable(context.resources,bitmap)
    val canvas = Canvas(bitmap)
    canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.ADD)
    val paintDot = Paint()
    paintDot.color = color
    paintDot.isFilterBitmap = true
    paintDot.style = Paint.Style.FILL
    paintDot.strokeWidth=dotWith.toFloat()
    paintDot.isAntiAlias=true
    var start=context.resources.getDimension(R.dimen.appfactory_liststyle_marginlr)-dotWith
    canvas.drawLine(start,0F,start,context.resources.getDimension(R.dimen.dimen1),paintDot)

    val paintLine = Paint()
    paintLine.color = 0xFFCCCCCC.toInt()
    paintLine.isFilterBitmap = true
    paintLine.style = Paint.Style.FILL
    paintLine.strokeWidth=dotWith.toFloat()
    paintLine.isAntiAlias=true
    canvas.drawLine(start*2,0F,listWidth-start,context.resources.getDimension(R.dimen.dimen1),paintLine)

    drawable.draw(canvas)
    return drawable

}